/* @(#)ManufactureDown.java   
 *
 * Project: GS-1
 *
 * Modify Information:
 * =============================================================================
 *   Author       Date       Description
 *   ------------ ---------- ---------------------------------------------------
 *   Jenny Li    2006-7-7     新增
 *
 * Copyright Notice:
 * =============================================================================
 *    Copyright (c) 2001-2006 Beijing HiTRUST Technology Co., Ltd. 1808 Room, 
 *        Science & Technology Building, No. 9 South Street, Zhong Guan Cun, 
 *        Haidian District, Beijing ,100081, China All rights reserved.
 *
 *    This software is the confidential and proprietary information of
 *        Beijing HiTRUST Technology Co., Ltd. ("Confidential Information").
 *        You shall not disclose such Confidential Information and shall use it
 *        only in accordance with the terms of the license agreement you entered
 *        into with HiTRUST.
 *
 * Warning:
 * =============================================================================
 * 
 */
package system.imp;

import java.io.DataInputStream;
import java.net.URL;

import framework.core.DBConnection;
import framework.core.ILoginContext;
import framework.core.LogWriter;

/**
 * 
 */
public class ManufactureDown {
    
    public void doDown(DBConnection con, ILoginContext loginContext){
        
        try {            
            LogWriter.info ("Begin to Down Manufacture Data... ");
            DataInputStream dis = null;
            String tDay=DateUtil.getNextUpDay(-1);
            //文件下载
            String Name="/" + "BSWZ" + "_Product_"+tDay+".xls";
            URL url = new URL("http" + "://"+ "192.168.0.25" + "/" + "v3/back/down" + Name);

            dis = new DataInputStream(url.openStream());
            
            //FormFile tFileName=f2;
            String tResult="";
            //UserBean tUserBean = (UserBean)aForm.getSession().getAttribute(BaseConstants.LOGIN);
            try{
                //导入产品信息
                tResult = GWFileUploadProcessor.batchImportManufacture(dis, con, loginContext);
            }catch(GWException e){
                LogWriter.error(e.getMessage());  
            }   
            //从返回的值中取得失败和成功的数据
            String tSuccess= tResult.split("-")[0];
            String tFail= tResult.split("-")[1];
            String tOutputPath = tResult.split("-")[2];
            if(Integer.parseInt(tFail)>0){
                LogWriter.error("Fail down output Manufacture path: " + tOutputPath);
                LogWriter.error("Fail import Manufacture count: " + tFail);                
            }
            LogWriter.info("Success import Manufacture count: " + tSuccess);
        }
        catch (Exception ex) {
            LogWriter.error("下载产品信息时出错!");
            LogWriter.error(ex.getMessage());
        }
        
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub

    }

}
